package zpe.controledeacesso.service;


import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Service;

import zpe.controledeacesso.model.bean.Permissoes;
import zpe.genericcrud.service.GenericService;

@Service
public class PermissoesService extends GenericService<Permissoes> {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 6739521789642283345L;

	@SuppressWarnings("unchecked")
	public List<Permissoes> consultaPermissoesByGrupo( Integer grupo ){
		DetachedCriteria c = DetachedCriteria.forClass(Permissoes.class).add(Restrictions.eq("grupoDeUsuario.id", grupo));		
		List<Permissoes> l = getDao().getEntityManager().findByCriteria(c);
		Collections.sort( l, new Comparator<Permissoes>() {
			public int compare(Permissoes o1, Permissoes o2) {
				return o1.getTransacao().getDescricao().compareToIgnoreCase( o2.getTransacao().getDescricao() );
			};
			});
		return l;
	}
	
	/*@SuppressWarnings("unchecked")
	public List<Permissoes> consultaPermissoesByGrupo( String grupo ){
		DetachedCriteria c = DetachedCriteria.forClass(Permissoes.class).add(Restrictions.eq("grupoDeUsuario.descricao", grupo)).addOrder( Order.asc("id") );
		return getDao().getEntityManager().findByCriteria(c);
	}*/	
}